//
//  UserHandler.m
//  mUBB
//
//  Created by Cosmin Stirbu on 2/23/13.
//  Copyright (c) 2013 Cosmin Stirbu. All rights reserved.
//

#import "UserHandler.h"
#import "UserProtocol.h"
#import "ConfigurationManager.h"

@implementation UserHandler

- (void)handleSuccess:(WSResponse *)response {
    NSDictionary *jsonResponse = [response.data objectFromJSONData];
    
    NSString *accessToken = [jsonResponse getJSONObjectForKey:TOKEN_TAG];
    NSString *userId = [jsonResponse getJSONObjectForKey:TEACHER_ID_TAG];
    
    [[ConfigurationManager instance] setApplicationConfigValue:userId forKey:USER_ID];
    [[ConfigurationManager instance] setApplicationConfigValue:accessToken forKey:ACCESS_TOKEN];
    
    [[ConfigurationManager instance] saveApplicationConfig];
    
    [self.delegate didSignInUserWithSuccessForTicket:self.ticket];
}

- (void)handleError:(WSError *)error {
    [self.delegate didSignInUserWithFailure:error forTicket:self.ticket];
}

@end
